package main

import (
	"fmt"
)

func main() {

	xunhuan1()

	xunhuan2()

	xunhuan3()

	xunhuan4()

	// 练习：打印偶数
	oddPrint(0, 50)

	// 打印矩形
	printStar(5, 9)

	// 打印99乘法表
	print99()

	color99()
}

func color99() {
	// 定义颜色常量
	const (
		Reset  = "\033[0m"
		Red    = "\033[31m"
		Green  = "\033[32m"
		Yellow = "\033[33m"
		Blue   = "\033[34m"
		Purple = "\033[35m"
		Cyan   = "\033[36m"
	)

	colors := []string{Red, Green, Yellow, Blue, Purple, Cyan}

	for i := 1; i <= 9; i++ {
		color := colors[(i-1)%len(colors)]
		for j := 1; j <= i; j++ {
			fmt.Printf("%s%d×%d=%-4d%s", color, j, i, i*j, Reset)
		}
		fmt.Println()
	}
}

func print99() {
	fmt.Println("┌─────────────────────────九九乘法表─────────────────────────┐")
	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			result := i * j
			fmt.Printf("%d*%d=%-2d ", i, j, result)
			//	fmt.Printf(strconv.Itoa(result))
		}
		fmt.Println("│")
	}
	fmt.Println("└─────────────────────────────────────────────────────────────┘")
}

func printStar(x int, y int) {

	for i := 0; i < x; i++ {
		for j := 0; j < y; j++ {
			fmt.Printf("*")
		}
		fmt.Println()
	}

}

func oddPrint(i int, i2 int) {
	for k := i; k <= i2; k++ {
		if k%2 == 0 {
			fmt.Println("偶数:", k)
		}
	}
}

func xunhuan1() {
	for i := 0; i < 10; i++ {
		fmt.Println(i)
	}
}

func xunhuan2() {
	i := 1

	for ; i < 10; i++ {
		fmt.Println(i)
	}
}

// 注意：避免死循环
func xunhuan3() {
	i := 1

	for i <= 10 {
		fmt.Println(i)
		i++
	}
}

func xunhuan4() {
	i := 1
	for {
		if i <= 10 {
			fmt.Println(i)
		} else {
			break
		}
		i++
	}
}
